Skip to content

[Feature] Added proxyReqOverride option #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

minho-comcom-ai
Copy link

Added proxyReqOverride option for overriding the original proxyReq proxy event.

@stegano
Copy link
Owner

stegano commented Aug 1, 2021

Hi, @minho-comcom-ai
Could you please explain in which cases this feature is needed?

@minho-comcom-ai
Copy link
Author

Hello, @stegano!
The purpose of this PR is to add headers (such as tracing) dynamically on each requests by following this http-proxy document.
There are headers option already in http-proxy, but it was globally affected to the same headers on every requests, not each requests.

@stegano
Copy link
Owner

stegano commented Aug 3, 2021

@minho-comcom-ai
Thanks for the explanation.

Adding header information dynamically to each request can be solved without modifying this library.

export default (req: NextApiRequest, res: NextApiResponse) => {
  if (req.url === '/api/test') {
    // Adding request headers dynamically
    req.headers['your-proxy-header'] = 'test';
  }
  nextHttpProxyMiddleware(req, res, {
    target: 'http://127.0.0.1:8099',
    pathRewrite: {
      '^/api': '',
    },
  });
};

And if you use the 'proxyReqOverride' you suggested, you won't be able to deal with the problem in #3.
Please let me know if I'm wrong.
Thank you 😀

@stegano
Copy link
Owner

stegano commented Sep 23, 2021

Close the issue. Please reopen if necessary.

@stegano stegano closed this Sep 23, 2021
stegano added a commit that referenced this pull request Jan 22, 2022
* Added function to directly access `http-proxy` instance
   - Improved to be able to directly bind event to `http-proxy` instance.

related: #50 #31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants